package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
public class ShopController {

    private static final String KEY = "shopStatus";

    @Autowired
    RedisTemplate redisTemplate;

    @ApiOperation("设置店铺状态")
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable String status){

        ValueOperations valueOperations = redisTemplate.opsForValue();

        valueOperations.set(KEY,status);

        return Result.success();
    }

    @ApiOperation("获取店铺状态")
    @GetMapping("/status")
    public Result getStatus(){

        ValueOperations valueOperations = redisTemplate.opsForValue();

        Integer status=Integer.parseInt((String) valueOperations.get(KEY));

        return Result.success(status);

    }
}
